package com.xingfly.school.student.acl.adapters;

import com.xingfly.school.course.domain.Course;
import com.xingfly.school.course.ohs.local.appservices.CourseAppService;
import com.xingfly.school.student.acl.pl.response.CourseResponse;
import com.xingfly.school.student.acl.ports.clients.CourseClient;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Created by SuperS on 2020/3/30.
 *
 * @author SuperS
 */
@Component
public class CourseClientAdapter implements CourseClient {

    @Resource
    private CourseAppService courseAppService;

    @Override
    public List<CourseResponse> findAllById(List<Long> ids) {
        List<Course> courses = courseAppService.findAllById(ids);
        return courses.stream().map(course -> CourseResponse.builder()
                .id(course.getId())
                .name(course.getName())
                .build()
        ).collect(Collectors.toList());
    }

    @Override
    public CourseResponse findById(Long courseId) {
        Course course = courseAppService.findById(courseId);
        return CourseResponse.builder().id(course.getId()).name(course.getName()).build();
    }

}
